package com.mz.mattress.client.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mz.mattress.api.entity.Device;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface DeviceMapper extends BaseMapper<Device> {

    @Update("update mz_device set last_heart=now(),online=1 where device_code=#{deviceCode} and deleted=0")
    int updateHeart(@Param("deviceCode") String deviceCode);

    @Update("update mz_device set sign=#{sign} where device_code=#{deviceCode} and deleted=0")
    int updateSign(@Param("deviceCode") String deviceCode, @Param("sign") Integer sign);

    @Update("update mz_device set online=#{online} where device_code=#{deviceCode} and deleted=0")
    int updateOnline(@Param("deviceCode") String deviceCode, @Param("online") Integer online);

    @Update("update mz_device set work_status=#{workStatus} where device_code=#{deviceCode} and deleted=0")
    int updateWorkStatus(@Param("deviceCode") String deviceCode, @Param("workStatus") Integer workStatus);

    @Select("select * from mz_device where device_code=#{deviceCode} and deleted=0")
    Device selectByDeviceCode(@Param("deviceCode") String deviceCode);

    //    @Select("select * from mz_device where isnull(merchant_id) and deleted=0")
//    @Select("select * from mz_device where id>339")
//    @Select("select * from mz_device where demo=1")
//    @Select("select * from mz_device where id>490 and demo=1")
    @Select("select * from mz_device where id>590")
    List<Device> selectAll();

    @Select("select device_code from mz_device where demo=1 and merchant_id>0 and deleted=0")
    List<String> selectDemoList();

    @Select("select device_code from mz_device where demo=1 and work_status=0 and merchant_id=#{merchantId} and deleted=0")
    List<String> selectAvailableByMerchantId(@Param("merchantId") Integer merchantId);

}
